<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Apply;
use Encore\Admin\Controllers\Dashboard;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Encore\Admin\Widgets\InfoBox;

class HomeController extends Controller
{
    public function index(Content $content)
    {
        return $content
            ->title('数据看板')
            ->row(function (Row $row) {
                $row->column(3, function (Column $column) {
                    $current_date = date('Y-m-d');
                    $result = Apply::where('visit_date', $current_date)->count();
                    $infoBox = new InfoBox('今日访客总数', 'users', 'aqua', '/admin/applies', $result);
                    $column->append($infoBox->render());
                });
                $row->column(3, function (Column $column) {
                    $current_date = date('Y-m-d');
                    $result = Apply::where('visit_date', $current_date)->where('status', 5)->count();
                    $infoBox = new InfoBox('今日已到访', 'arrows', 'aqua', '/admin/applies', $result);
                    $column->append($infoBox->render());
                });
                $row->column(3, function (Column $column) {
                    $current_date = date('Y-m-d');
                    $result = Apply::where('visit_date', $current_date)->where('status', 2)->count();
                    $infoBox = new InfoBox('今日未到访', 'bank', 'aqua', '/admin/applies', $result);
                    $column->append($infoBox->render());
                });
                $row->column(3, function (Column $column) {
                    $result = Apply::where('status', 1)->count();
                    $infoBox = new InfoBox('待审核', 'book', 'aqua', '/admin/applies', $result);
                    $column->append($infoBox->render());
                });
            });
    }
}
